Skip to content

perf(atlas-search): run hybrid branches concurrently (#12900 thread 1) - #13039

Merged
dezren39 merged 1 commit into
mainfrom
lane-kl-12900
Nov 23, 2026
Merged

dezren39 merged 1 commit into
mainfrom
lane-kl-12900

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Refs #12900 — thread 1 of 3 (parallel branch execution in the Python CLI). The issue stays open: thread 2 is a product decision (multi-client service shape) and thread 3 is the nix-packaged binary swap.

What changed (pkgs/atlas-search/atlas_search.py)

A hybrid query's FTS and vector branches are independent and join only at RRF fusion, but run_search executed them strictly serially on every backend shape. Now:

  • New run_branches helper: with two or more branches they run concurrently on a thread pool and are collected by name — fusion order, and therefore the output envelope, is unchanged. A single branch runs inline, so fts-only / vector-only keep their exact old shape. die() in a branch is ferried back and re-raised as SystemExit on the calling thread with its exit code intact.
  • Turso scan mode: one pipeline per branch instead of both statements in a single pipeline (a pipeline executes its statements sequentially server-side, so the batched shape serialized the branches). Turso index mode: the FTS pipeline and turso_index_branch now overlap.
  • Local backend: LocalBackend.con is now a per-thread connection (property + thread-local). The TEMP views of _setup_views and the ATTACHes of load_matrix are per-connection state, so branch workers each get their own connection with the same view setup instead of sharing one.

Verification

  • New pkgs/atlas-search/tests/test_branch_concurrency.py (5 tests, all passing on the laptop with the v3-venv python): hybrid envelope concurrent == forced-serial == the committed recording in fixtures/core-expectations.json; fts-only and vector-only envelopes match their recordings; with 0.6 s sleeps injected at both branch entry points the serial shape takes ≥1.15 s and the concurrent shape <1.0 s; die() inside a branch surfaces as SystemExit with its code on both the local and turso paths.
  • fixtures/gen_core_fixtures.py re-run against this code: the regenerated core-expectations.json is value-identical to the committed recording (all 12 search cases, get-chunk cases, and the turso SQL fixtures) — the file itself is not in this PR.
  • Existing tools/tests suites still pass (test_disclosure 8, test_note_promotion_sweep 5).

See it in action
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

The FTS and vector branches of a hybrid query are independent and
join only at RRF fusion, but run_search executed them strictly
serially on every backend shape: the local FTS query finished before
the vector scan started, the turso index path ran its FTS pipeline
to completion before the index branch, and the turso scan path sent
both statements in one pipeline, which executes sequentially
server-side.

They now run concurrently through run_branches (a thread pool,
results collected by name; a single branch still runs inline, so
fts-only and vector-only keep their exact old shape). LocalBackend
gives each thread its own sqlite connection — the TEMP views of
_setup_views and the ATTACHes of load_matrix are per-connection
state — so branch workers never share one. die() inside a branch is
ferried back and re-raised as SystemExit on the calling thread with
its exit code intact.

Output is unchanged: fixtures/gen_core_fixtures.py regenerated
against this code produces a core-expectations.json value-identical
to the committed recording, and the new tests in
tests/test_branch_concurrency.py pin serial == concurrent ==
recorded envelopes, real overlap under slowed branch entry points,
and die() propagation on both backend shapes.

Refs #12900
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 31247da2-7a8a-4343-9c41-6e3fa16a2884
Commits

Reviewing files that changed from the base of the PR and between bae767e and 4fa9199.

Files selected for processing: 2

  • pkgs/atlas-search/atlas_search.py
  • pkgs/atlas-search/tests/test_branch_concurrency.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T07:32:50.230708Z 4fa9199 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39
dezren39 merged commit 03e5d20 into main Nov 23, 2026
2 checks passed
@dezren39
dezren39 deleted the lane-kl-12900 branch November 23, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant